<?php
/**
 * Created by PhpStorm.
 * User: deng
 * Date: 2015/2/26
 * Time: 18:11
 */

namespace Users\Controller;


use Common\Controller\RestFulApiController;


/**
 * Class BaseUserController
 * @package User\Controller
 */
class BaseUserController extends RestFulApiController
{

    function __construct()
    {
        parent::__construct();
    }

    public function multiple()
    {
        switch ($this->_method) {
            case 'get':
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
                break;
            case 'post':
                return $this->create();
                break;
            case 'put':
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
                break;
            case 'delete':
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
                break;
            case 'head':
                break;
            case 'options':
                return $this->options('Access-Control-Allow-Methods: GET, POST, OPTIONS');
                break;
            default:
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
        }
    }

    public function single()
    {
        $id = $_REQUEST['userId'];
        switch ($this->_method) {
            case 'get':
                return $this->view($id);
                break;
            case 'post':
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
                break;
            case 'put':
                return $this->update($id);
                break;
            case 'delete':
                return $this->delete($id);
                break;
            case 'head':
                break;
            case 'options':
                return $this->options(['get', 'put', 'delete', 'head', 'options']);
                break;
            default:
                E(C('CODE.METHOD_NOT_ALLOWED')['msg'], $status = C('CODE.METHOD_NOT_ALLOWED')['code']);
        }
    }
}